using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Travel.UserControls
{
    public partial class UserManage : UserControl
    {
        public UserManage()
        {
            InitializeComponent();
        }

        // The ListView Sorter
        private Travel.Library.ListViewItemComparer _lvwItemComparer = new Travel.Library.ListViewItemComparer();

        /// <summary>
        /// Show the infomation of user.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listUser_Click(object sender, EventArgs e)
        {
            new UserInfo().ShowDialog();
        }

        private void listUser_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            // Determine if clicked column is already the column that is being sorted.
            if (e.Column == _lvwItemComparer.SortColumn)
            {
                // Reverse the current sort direction for this column.
                if (_lvwItemComparer.Order == SortOrder.Ascending)
                {
                    _lvwItemComparer.Order = SortOrder.Descending;
                }
                else
                {
                    _lvwItemComparer.Order = SortOrder.Ascending;
                }
            }
            else
            {
                // Set the column number that is to be sorted; default to ascending.
                _lvwItemComparer.SortColumn = e.Column;
                _lvwItemComparer.Order = SortOrder.Ascending;
            }

            // Perform the sort with these new sort options.
            this.listUser.Sort();
        }

        private void UserManage_Load(object sender, EventArgs e)
        {
            this.listUser.ListViewItemSorter = _lvwItemComparer;
        }
    }
}
